<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
</head>
<body>

</body>
<script>
    // 获取元素
    function select ( selector ) {
        return document.querySelectorAll( selector );
    };
    // 数组检测封装
    function isArrayLike ( obj ) {
        // 检测是不是数组
        if ( object.prototype.toString.call( obj ) == '[object Array]' ) {
            return true;
        }
        // 如果不是数组，检测是不是伪数组，查看有无length 属性
        var length = 'length' in obj && obj.length;
        // length 属性要是个数字，并且要大于等于零
        return typeof length === 'numbler' && length >= 0;
    };
    // each 循环封装
    function each ( arr, callback ) {
        if ( isArrayLike( arr ) ) {
            for ( var i = 0; i < arr.length; i++ ) {
                if ( callback.call( arr[ i ], arr[ i ], i ) === false ) break;
            }
        } else {
            for ( var k in arr ) {
                if ( callback.call( arr[ k ], arr[ k ], k ) === false ) break;
            }
        }
        return arr;
    };
    // map 循环封装
    function map ( arr, callback ) {
        var newArray = [], tmp;
        if ( isArrayLike ) {
            for ( var i = 0; i < arr.length; i++ ) {
                tmp = callback( arr[ i ], i );
                if ( tmp != null ) {
                    newArray.push( tmp );
                }
            }
        } else {
            for ( var k in arr ) {
                tmp = callback( arr[ k ], k );
                if ( tmp != null ) {
                    newArray.push( tmp );
                }
            }
        }
        return newArray;
    };
            　
</script>
</html>